let evn = null
const LAND_MARK_MAP_ID = 1;

wx.miniProgram.getEnv(function (res) {
  // console.log(res.miniprogram) // true
  console.log(res);
  evn = res;
})

export default {
  getMarkMapId() {
    return LAND_MARK_MAP_ID
  },
  getAllQueryString: function (url = null) {
    if (!url) url = window.location.href;
    var pattern = /(\?|&)\w+=\w+((?=&)|$)/g;
    var mat = url.match(pattern);
    if (mat == null) return {};
    var obj = {};
    for (var i = 0; i < mat.length; i++) {
      var str = mat[i].substr(1);
      var temp = str.split('=');
      obj[temp[0]] = temp[1];
    }
    return obj;
  },
  isMiniProgram() {
    return evn && evn.miniprogram
  },
  navigateTo(opts) {
    if (this.isMiniProgram()) {
      wx.miniProgram.navigateTo(opts)
    } else {
      window.location.href = opts.webUrl
    }
  },
  navigateBack(delta = 1) {
    if (this.isMiniProgram()) {
      wx.miniProgram.navigateBack({
        delta: delta
      })
    }
  },
  postMessage(data) {
    if (this.isMiniProgram() && wx.miniProgram.postMessage) {
      wx.miniProgram.postMessage(data)
    }
  }
}